import $V from './$V';

export default function rsi(price, length) {
    let rsiValue = $V.init(price.length,50);
    let diffOfPrice = $V.init(price.length,0);
    diffOfPrice = $V.copy_by_range(diffOfPrice,$V.arange(1,price.length),$V.sub($V.subv(price,1,price.length),$V.subv(price,0,price.length-1)));
    for(let i = length;i < price.length;i++){
        let temp = $V.subv(diffOfPrice,i-length,i-1);
        rsiValue[i] = $V.sum($V.vector_of_index(temp,$V.where(temp,'>',0)))/$V.sum($V.abs(temp))*100;
    }
    return rsiValue;
}
